import React, { Component } from 'react';
import './Entry.scss'
import { index_nav } from '../../utils/api'

class Entry extends Component {
    // 挂载期(挂载期的方法会自动执行，而且只执行一次)
    constructor(props) {//这个函数会在组件挂载前就执行，组件并没有显示在页面上
        super(props);
        // console.log('constructor');
        this.state = {
            list: []
        }//初始化组件状态
    }
    componentDidMount() {
        index_nav().then((res) => {
            console.log(res.data)
            console.log(res.data.list)
            this.setState(
                this.state.list = res.data.list
            )
        })
    }
    render() {
        return (
            <div className='list'>
                <span>1分抵1元。请您点击此处查看《购物须知》</span>
                {
                    this.state.list.map((item, index) => {
                        return (
                            <div className="cate" key={index}>
                                <img src={item.pic} />
                                <div className="name">{item.name}</div>
                            </div>
                        )
                    })
                }
            </div>
        );
    }
}

export default Entry;